# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Geometry-Geometry::Point.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';
use strict;
use warnings;

use Test::More 'no_plan';
use Test::Fatal;
$| = 1;
BEGIN { use_ok('Geometry::Point') };

my $point = Geometry::Point->new( x => 1, y => 2 );
isa_ok( $point, 'Geometry::Point' );
isa_ok( $point, 'Moose::Object' );

is( $point->x, 1, '... got the right value for x' );
is( $point->y, 2, '... got the right value for y' );

$point->y(10);
is( $point->y, 10, '... got the right (changed) value for y' );

isnt(
    exception {
        $point->y('Foo');
    },
    undef,
    '... cannot assign a non-Int to y'
);

isnt(
    exception {
        Geometry::Point->new();
    },
    undef,
    '... must provide required attributes to new'
);

is($point->toString, 'x = 1, y = 10', '... got the correct string');

$point->clear();

is( $point->x, 0, '... got the right (cleared) value for x' );
is( $point->y, 0, '... got the right (cleared) value for y' );

# check the type constraints on the constructor

is(
    exception {
        Geometry::Point->new( x => 0, y => 0 );
    },
    undef,
    '... can assign a 0 to x and y'
);

isnt(
    exception {
        Geometry::Point->new( x => 10, y => 'Foo' );
    },
    undef,
    '... cannot assign a non-Int to y'
);

isnt(
    exception {
        Geometry::Point->new( x => 'Foo', y => 10 );
    },
    undef,
    '... cannot assign a non-Int to x'
);

# Geometry::Point3D

my $point3d = Geometry::Point3D->new( { x => 10, y => 15, z => 3 } );
isa_ok( $point3d, 'Geometry::Point3D' );
isa_ok( $point3d, 'Geometry::Point' );
isa_ok( $point3d, 'Moose::Object' );

is( $point3d->x,     10, '... got the right value for x' );
is( $point3d->y,     15, '... got the right value for y' );
is( $point3d->{'z'}, 3,  '... got the right value for z' );

is($point3d->toString, 'x = 10, y = 15, z = 3', '... got the correct string');

$point3d->clear();

is( $point3d->x, 0, '... got the right (cleared) value for x' );
is( $point3d->y, 0, '... got the right (cleared) value for y' );
is( $point3d->z, 0, '... got the right (cleared) value for z' );

isnt(
    exception {
        Geometry::Point3D->new( x => 10, y => 'Foo', z => 3 );
    },
    undef,
    '... cannot assign a non-Int to y'
);

isnt(
    exception {
        Geometry::Point3D->new( x => 'Foo', y => 10, z => 3 );
    },
    undef,
    '... cannot assign a non-Int to x'
);

isnt(
    exception {
        Geometry::Point3D->new( x => 0, y => 10, z => 'Bar' );
    },
    undef,
    '... cannot assign a non-Int to z'
);

isnt(
    exception {
        Geometry::Point3D->new( x => 10, y => 3 );
    },
    undef,
    '... z is a required attribute for Geometry::Point3D'
);

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

